package org.groupg.project.shell;

import groovy.lang.GroovyShell;

public class GroovyShellExample {
    public static void main(String[] args) {
        GroovyShell shell = new GroovyShell();

        // Groovy 脚本作为字符串
        String script = "def greet(name) { return \"Hello, $name!\" }\n" +
                        "greet('Java')";

        try {
            // 执行脚本并获取结果
            Object result = shell.evaluate(script);

            // 输出结果
            System.out.println("Result from Groovy: " + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}